//
//  ArchivesAPI.swift
//  Health-Doctor
//
//  Created by 勇胡 on 2024/8/20.
//  Copyright © 2024 掌上卫健. All rights reserved.
//云平台直连

import Foundation
import Moya

let archivesProvider = MoyaProvider<ArchivesAction>(session:ArchivesAction.custoSession(),plugins:NetworkLoggerPlugin.plugins())

enum ArchivesAction {
    //缓存云平台档案详情数据
    case cacheCloudArchivesToWoniu(param:[String:Any])
    //蜗牛个人档案数据转云平台档案数据结构
    case changeSubmitWCDataStyle(param:[String:Any])
    //云平台家庭档案详情转蜗牛家庭档案详情
    case cloudFamilyToLocalFamily(param:[String:Any])
    //云平台家庭列表 转蜗牛家庭档案列表
    case cloudFamilyListToLocalList(param:[String:Any])
}

extension ArchivesAction: TargetType {
    var baseURL: URL {
        return URL(string: "https://wnjk.2woniu.cn")!
    }
    
    var path: String {
        
        var detailPath = ""
        switch self {
        case .cacheCloudArchivesToWoniu:
            detailPath = "cloudauth/resident/archives/remote/saveLocal"
        case .changeSubmitWCDataStyle:
            detailPath = "cloudauth/resident/archives/merge/localToYpt"
        case .cloudFamilyToLocalFamily:
            detailPath = "cloudauth/family/archives/trans/detail"
        case .cloudFamilyListToLocalList:
            detailPath = "cloudauth/family/archives/trans/list"
        }
        return detailPath
    }
    
    var params: [String:Any] {
        var params:[String:Any] = [:]
        switch self {
        case 
            .cacheCloudArchivesToWoniu(let param),
            .changeSubmitWCDataStyle(let param),
            .cloudFamilyToLocalFamily(let param),
            .cloudFamilyListToLocalList(let param):
            for (k,v) in param {
                params[k] = v
            }
            
        }
        return params
        
    }
    
    var headers: [String : String]? {
        return getHttpHeader(token: "")
    }
    
    
    var method: Moya.Method {
        return .post
    }
    
    var sampleData: Data {
        return "{}".data(using: String.Encoding.utf8)!
    }
    
    var task: Task {
        if self.method == .get {
            return.requestParameters(parameters: self.params, encoding:GetEncoding())
        }
        return.requestParameters(parameters: self.params, encoding:JSONEncoding())
    }
}
